package org.example.exception;


import lombok.extern.slf4j.Slf4j;
import org.example.result.Result;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.net.ConnectException;

@Slf4j
@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler(Exception.class)
    public Result handlerException(Exception e){
        log.error("异常信息:{}",e.getMessage());
        e.printStackTrace();
        return Result.error((StringUtils.hasLength(e.getMessage()) ? e.getMessage() : "gateway服务器异常"));
    }


    @ExceptionHandler(ConnectException.class)
    public Result connectException(ConnectException e){
        log.error("异常信息:{}",e.getMessage());
        e.printStackTrace();
        return Result.error((StringUtils.hasLength(e.getMessage()) ? "连接超时" : "gateway服务器异常"));
    }

}
